package top.zhangjianyong.blog.manage.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.blog.annotation.Permission;
import top.zhangjianyong.blog.enums.RoleKeys;
import top.zhangjianyong.blog.params.role.*;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.RoleService;

/**
 * 角色Controller
 *
 * @author HDN
 * @since 2024/7/22 上午12:16
 */
@Permission(roles = {RoleKeys.ADMIN})
@RequestMapping("/role")
@RestController
public class RoleController {

  private final RoleService roleService;

  public RoleController(RoleService roleService) {
    this.roleService = roleService;
  }

  @PostMapping("/page")
  public ApiResponse page(@RequestBody @Validated RolePageParam param) {
    return roleService.page(param);
  }

  @PostMapping("/remove")
  public ApiResponse remove(@RequestBody @Validated RoleRemoveParam param) {
    return roleService.remove(param);
  }

  @PostMapping("/saveOrUpdate")
  public ApiResponse saveOrUpdate(@RequestBody @Validated RoleSaveOrUpdateParam param) {
    return roleService.saveOrUpdate(param);
  }

  @PostMapping("/menus")
  public ApiResponse menus(@RequestBody @Validated RoleMenusParam param) {
    return roleService.menus(param);
  }

  @PostMapping("/menus/update")
  public ApiResponse menusUpdate(@RequestBody @Validated RoleMenusUpdateParam param) {
    return roleService.menusUpdate(param);
  }

  @PostMapping("/list")
  public ApiResponse list(@RequestBody @Validated RoleListParam param) {
    return roleService.list(param);
  }
}
